package com.zzty.controller;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zzty.entity.UserAdmin;
import com.zzty.dao.UserDao;

/**
 * Servlet implementation class LoginController
 */
@WebServlet("/LoginController")
public class LoginController extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");

		UserDao uDao = new UserDao();
		boolean flag = false;
			
			try {
			UserAdmin u = uDao.getUserByName(name);
			String pwdDB = u.getPwd();
			if(pwdDB!=null&&pwdDB.equals(pwd)){
				flag = true;
			}
			} catch (Exception e) {
				e.printStackTrace();
			}
		
		if(flag){
			request.getRequestDispatcher("bookList.jsp").forward(request, response);;
		}else{
			request.getRequestDispatcher("fail.html").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
